﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Web;
using System.Web.SessionState;
using WF.Common;

namespace WF.Web.Pages
{
    /// <summary>
    /// HandlerDeptForRpt 的摘要说明
    /// </summary>
    public class HandlerDeptForRpt : HrBasePage, IHttpHandler, IRequiresSessionState
    {
        public override void ProcessRequest(HttpContext context)
        {
            if (base.Valid)
            {
                DataContractJsonSerializer serializer = null;
                List<vDeptList> data = new List<vDeptList>();
                if (context.Request["args"] == "get")
                {
                    data = (from a in new ConfigHelper().ReportGroups.Trim().Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                            select new vDeptList
                            {
                                DeptName = a.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0],
                                DeptCode = a.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[1]
                            }).ToList();
                    serializer = new DataContractJsonSerializer(data.GetType());
                }
                if (serializer != null)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        serializer.WriteObject(ms, data);
                        context.Response.Write(Encoding.UTF8.GetString(ms.ToArray()));
                        context.Response.End();
                    }
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}